package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.vo.CategoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Author Yjr
 * @Date 2025/5/16 20:54
 */
@Slf4j
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类管理")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 添加菜品分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation("添加分类")
    @PostMapping
    public Result add(@RequestBody CategoryDTO categoryDTO){

        categoryService.add(categoryDTO);
        return Result.success();
    }

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageList(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult=categoryService.pageList(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除分类
     * @param id
     * @return
     */
    @ApiOperation("删除分类")
    @DeleteMapping
    public Result remove(@RequestParam Long id){
        categoryService.removeById(id);
        return Result.success();
    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation("修改分类")
    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }
    /**
     * 修改分类状态为禁用
     * @param
     * @return
     */
    @ApiOperation("修改分类状态为禁用")
    @PostMapping("/status/0")
    public Result banStatus( Long id){
        categoryService.updateStatus(id);
        return Result.success();
    }

    /**
     * 修改分类状态为启用
     * @param
     * @return
     */
    @ApiOperation("修改分类状态为启用")
    @PostMapping("/status/1")
    public Result openStatus( Long id){
        categoryService.updateStatus(id);
        return Result.success();
    }

    /**
     * 根据类型查询分类
     * @return
     */
    @ApiOperation("根据类型查询分类")
    @GetMapping("/list")
    public Result findByTypeList(@RequestParam("type") Integer type){
        List<CategoryVo> categoryVoList= categoryService.findByTypeList(type);

        return Result.success(categoryVoList);
    }
}
